package com.hcxdi.base.presenter;

import android.support.annotation.Nullable;

import java.lang.ref.WeakReference;

/**
 * Created by jiajiabao on 16-11-14.
 */

public  class AbstractPresenter<V> implements Presenter<V> {

    private WeakReference<V> mView;

    @Override
    public void onViewAttached(V view) {
        mView = new WeakReference<>(view);
    }

    @Override
    public void onViewDetached() {
    }

    @Override
    public void onDestroyed() {
        mView = null;
    }

    @Nullable
    @Override
    public V getView() {
        return mView == null ? null : mView.get();
    }

    @Override
    public boolean isViewAttached() {
        return mView != null && mView.get() != null;
    }
}